﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PJ.Business
{
    /// <summary>
    /// <see cref="IItem"/> services interface
    /// </summary>
    public interface IItemService : IEntityService
    {
        /// <summary>
        /// Gets the item
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given name does not exist.</exception>
        IItem GetByName(string name);

        /// <summary>
        /// Gets the item from cache first. If not found in cache, gets the item from provider.
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given name does not exist.</exception>
        IItem CachedGetByName(string name);

        /// <summary>
        /// Finds the item
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        IItem FindByName(string name);

        /// <summary>
        /// Finds the item from cache first. If not found in cache, finds the item from provider.
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        IEntity CachedFindByName(string name);

        /// <summary>
        /// Searchs the Item that match the given criteria
        /// </summary>
        /// <param name="searchText">search criteria</param>
        /// <returns>Collection of Item global ids</returns>
        /// <exception cref="ArgumentNullException">If <paramref cref="searchText"/> is <see langref="null"/> or empty.</exception>
        IEnumerable<string> Search(string searchText);
    }

    /// <summary>
    /// <see cref="IItem"/> services interface
    /// </summary>
    /// <typeparam name="TIItem">Business <see cref="IItem">Item</see> interface type</typeparam>
    public interface IItemService<TIItem> : IEntityService<TIItem>, IItemService
        where TIItem : class, IItem
    {
        /// <summary>
        /// Gets the item
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given name does not exist.</exception>
        new TIItem GetByName(string name);

        /// <summary>
        /// Gets the item from cache first. If not found in cache, gets the item from provider.
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        /// <exception cref="DataNotFoundException">If the item with the given name does not exist.</exception>
        new TIItem CachedGetByName(string name);

        /// <summary>
        /// Finds the item
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        new TIItem FindByName(string name);

        /// <summary>
        /// Finds the item from cache first. If not found in cache, finds the item from provider.
        /// </summary>
        /// <param name="name">Item name</param>
        /// <returns>The item instance if found else null.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langref="null"/> or empty.</exception>
        new TIItem CachedFindByName(string name);
    }
}
